<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: url('https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_1280.jpg') no-repeat;
            background-size: 100% 130%;
        }

        #login_box {
            width: 20%;
            height: 400px;
            background-color: #00000060;
            margin: auto;
            margin-top: 10%;
            text-align: center;
            border-radius: 10px;
            padding: 50px 50px;
        }

        h2 {
            color: #ffffff90;
            margin-top: 5%;
        }

        #input-box {
            margin-top: 5%;
        }

        span {
            color: #fff;
        }

        input {
            border: 0;
            width: 60%;
            font-size: 15px;
            color: #fff;
            background: transparent;
            border-bottom: 2px solid #fff;
            padding: 5px 10px;
            outline: none;
            margin-top: 10px;
        }

        button {
            margin-top: 50px;
            width: 60%;
            height: 30px;
            border-radius: 10px;
            border: 0;
            color: #fff;
            text-align: center;
            line-height: 30px;
            font-size: 15px;
            background-image: linear-gradient(to right, #30cfd0, #330867);
        }

        #sign_up {
            margin-top: 45%;
            margin-left: 60%;
        }

        a {
            color: #b94648;
        }
    </style>
</head>

<body>

    <div id="login_box">
        <h2>LOGIN</h2>
        <div id="input_box">
            <input type="text" name="username" placeholder="请输入用户名" id="username">
        </div>
        <div class="input_box">
            <input type="password" name="password" placeholder="请输入密码" id="password">
        </div>
        <div id="msg"></div>
        <br>
        <button type="button" onclick="tj()">登录</button><br>
    </div>

    <script>
        function tj() {
            let username = document.getElementById('username');
            let password = document.getElementById('password');
            let data = {
                'username': username.value,
                'password': password.value
            }
            // console.log(data);
            const xhr = new XMLHttpRequest()
            let url = ''
            xhr.open('post', url, true)
            xhr.send(JSON.stringify(data))
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    data = JSON.parse(xhr.responseText)
                    console.log(data);
                    let mssg = document.getElementById('msg');
                    mssg.innerHTML = data.msg;
                   if(data.msg==='登陆成功'){
                    window.location.href='/index';
                   }
                }
            }
        }

    </script>
</body>

</html>